﻿using MediatR;
using W.Common.Enum;
using W.Purchase.API.Application.Command.PayableCommand;
using W.Purchase.Repository.Impl;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.PayableCommandHandler
{
    public class PayableCreateCommandHandler:IRequestHandler<PayableCreateCommand,int>
    {
        private readonly IPayableRepository _ipayableRepository;
        public PayableCreateCommandHandler(IPayableRepository payableRepository)
        {
            _ipayableRepository = payableRepository;
        }

        public async Task<int> Handle(PayableCreateCommand request, CancellationToken cancellationToken)
        {
            return await _ipayableRepository.AddAsync(new Domain.Payable
            {
                PayableId = request.PayableId,
                PayableSerialNumber = request.PayableSerialNumber,
                PayableName = request.PayableName,
                FinanceTypeName = request.FinanceTypeName,
                EndDate = request.EndDate,
                Payer = request.Payer,
                Payee = request.Payee,
                PayableMoney = request.PayableMoney,
                ActuallyPaidMoney = 0,
                ResidueMoney = 0,
                Status = ReceivableStatus.等待审核,
                PaymentNum = request.PaymentNum,
                Receivableremark = request.Receivableremark,
                office_id = request.office_id,
                user_id = request.user_id,
                CreateName = request.CreateName,
                CreateTime = DateTime.Now,
                IsDelete = false,
                StyleStatus="应付"
            });
        }
    }
}
